import service from './axiosService.js'
import base from './apiPaths.js'

// 注册验证码
export const SendVerificationCode = (params)=>{
    return service.post(base.getCode,params)
}

// 封装用户注册账号的请求函数
export const GetRegisterAccount = (params)=>{
    return service.post(base.getRegister,params)
}

// 封装用户登录平台的请求函数
export const login = (params)=>{
    return service.post(base.getLogin,params)
}

// 获取当前用户信息
export const getUserProfile = () => {
    return service.get(base.userProfile)
}

// 更新用户信息
export const updateUserProfile = (data) => {
    return service.put(base.updateProfile, data)
}

// 项目相关接口
export const getProjects = (params) => {
    return service.get(base.projects, {params: params})
}

export const getProjectDetail = (id) => {
    return service.get(`${base.projects}${id}/`)
}

export const createProject = (data) => {
    return service.post(base.projects, data)
}

export const updateProject = (id, data) => {
    return service.put(`${base.projects}${id}/`, data)
}

export const deleteProject = (id) => {
    return service.delete(`${base.projects}${id}/`)
}

// 测试用例相关接口
export const getCases = (params) => {
    return service.get(base.cases, {params: params})
}

export const getCaseDetail = (id) => {
    return service.get(`${base.cases}${id}/`)
}

export const createCase = (data) => {
    return service.post(base.cases, data)
}

export const updateCase = (id, data) => {
    return service.put(`${base.cases}${id}/`, data)
}

export const deleteCase = (id) => {
    return service.delete(`${base.cases}${id}/`)
}

// 执行测试用例
export const executeCase = (id, data) => {
    return service.post(`${base.cases}${id}/execute/`, data)
}

// 测试套件相关接口
export const getSuites = (params) => {
    return service.get(base.suites, {params: params})
}

export const getSuiteDetail = (id) => {
    return service.get(`${base.suites}${id}/`)
}

export const createSuite = (data) => {
    return service.post(base.suites, data)
}

export const updateSuite = (id, data) => {
    return service.put(`${base.suites}${id}/`, data)
}

export const deleteSuite = (id) => {
    return service.delete(`${base.suites}${id}/`)
}

// 执行测试套件
export const executeSuite = (id, data) => {
    return service.post(`${base.suites}${id}/execute/`, data)
}

// 日志相关接口
export const getLogs = (params) => {
    return service.get(base.logs, {params: params})
}

export const getLogDetail = (id) => {
    return service.get(`${base.logs}${id}/`)
}

export const createLog = (data) => {
    return service.post(base.logs, data)
}

export const updateLog = (id, data) => {
    return service.put(`${base.logs}${id}/`, data)
}

export const deleteLog = (id) => {
    return service.delete(`${base.logs}${id}/`)
}

export const getLogStatistics = () => {
    return service.get(base.logsStatistics)
}

// 管理员用户管理接口
export const getUserList = (params) => {
    return service.get(base.userList, {params: params})
}

export const assignUserDepartment = (id, data) => {
    return service.put(base.assignDepartment.replace('{id}', id), data)
}

// 头像上传
export const uploadAvatar = (formData) => {
    return service.post(base.uploadAvatar, formData, {
        headers: {
            'Content-Type': 'multipart/form-data'
        }
    })
}

// 部门管理接口
export const getDepartments = (params) => {
    return service.get(base.departments, {params: params})
}

export const createDepartment = (data) => {
    return service.post(base.departments, data)
}

export const updateDepartment = (id, data) => {
    return service.put(`${base.departments}${id}/`, data)
}

export const deleteDepartment = (id) => {
    return service.delete(`${base.departments}${id}/`)
}

export const getDepartmentTree = () => {
    return service.get(base.departmentTree)
}

export const getDepartmentOptions = () => {
    return service.get(base.departmentOptions)
}

// 激活用户
export const activateUser = (id, data) => {
    return service.put(base.activateUser.replace('{id}', id), data)
}

// 激活部门
export const activateDepartment = (id, data) => {
    return service.put(`${base.departments}${id}/activate_department/`, data)
}

// 环境配置相关接口
export const getEnvironments = (params) => {
    return service.get(base.environments, {params: params})
}

export const getEnvironmentDetail = (id) => {
    return service.get(`${base.environments}${id}/`)
}

export const createEnvironment = (data) => {
    return service.post(base.environments, data)
}

export const updateEnvironment = (id, data) => {
    return service.put(`${base.environments}${id}/`, data)
}

export const deleteEnvironment = (id) => {
    return service.delete(`${base.environments}${id}/`)
}